<template>
  <div>
    <div class="crumbs">
      <router-link to="/certificate/distributeruleadd">
        <el-button type="success">添加积分派发</el-button>
      </router-link>
    </div>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="ID" width="100"></el-table-column>
      <el-table-column prop="system_user_name" label="派发人" width="100"></el-table-column>
      <el-table-column prop="fund_type" label="所需资产类型" :formatter="typeFormat"></el-table-column>
      <el-table-column prop="fund" label="所需资产" :formatter="fundFormat"></el-table-column>
      <el-table-column prop="integral" label="积分"></el-table-column>
      <el-table-column prop="remark" label="备注"></el-table-column>
      <el-table-column prop="create_time" label="派发时间"></el-table-column>
      <el-table-column prop="status_text" label="状态"></el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        @current-change ="handleCurrentChange"
        layout="total, prev, pager, next"
        :current-page="textData.current_page"
        :page-size="textData.per_page"
        :total="textData.total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  import { mapState } from 'vuex'

  export default {
    data () {
      return {
      }
    },
    computed: {
      ...mapState({
        tableData: state => state.certificate.distributeRuleList,
        textData: state => state.certificate.pageData
      })
    },
    created () {
      this.distributeRuleList()
    },
    methods: {
      async distributeRuleList () {
        let payload = {
          page: this.textData.current_page,
          listRows: this.textData.per_page
        }
        await this.$store.dispatch('certificate/distributeRuleList', payload)
      },
      handleCurrentChange (val) {
        this.textData.current_page = val
        this.distributeRuleList()
      },
      typeFormat: function (value) {
        if (value.fund_type === 'currency') {
          return '亚数币(个)'
        } else {
          return '人民币(元)'
        }
      },
      fundFormat: function (value) {
        if (value.fund_type === 'currency') {
          return value.fund
        } else {
          return Number(value.fund / 100)
        }
      }
    }
  }
</script>
